<?php
namespace addon\wechat_config\validate;
use app\common\validate\ValidateBase;
use think\Db;
class User extends ValidateBase
{
    // 验证规则
    protected $rule = [
        'username'              => 'require|length:3,30',
        'openid'                => 'require',
        'password'              => 'require|length:6,30',       // 密码长度6-18位
        'confirm_password'      => 'require|confirm:password',
        'integral'              => 'require|number|>=:0',
        'money'                 => 'require|number|>=:0',
        'verify'                => 'require|captcha',
        'code'                  => 'require|checkCode',
        'nickname'              => 'require',
        'city_id'               => 'require|regex:\d{1,}',
        'gender'                => 'require',
        'signature'             => 'require',
        'oldpassword'           => 'require|checkOldpassword'
    ];

    // 应用场景
    protected $scene = [
        'add'               => ['nickname',"openid",'headimg'],
        'update_base'       => ['nickname','integral','money'],
        'update'            => ['password','confirm_password','nickname','integral','money'],
        'login'             => ['username',"password","verify"],
        'updatebase'        => ['nickname'],
        'reg'      =>  ['username'=>'require|unique:User','nickname','password','confirm_password','verify'],
    ];
    protected $message  =   [
        'username.require'              => '用户名必须',
        'username.length'               => '用户名长度3-30位',
        'username.openid'               => 'openid非法',
        'username.unique'               => '该用户名已经存在',
        'password.require'              => '密码必须',
        'integral.require'              => '积分必须',
        'integral.number'               => '积分必须是数字',
        'integral.egt'                  => '积分必须大于等于0',
        'money.number'                  => '余额必须是数字',
        'money.egt'                     => '余额必须大于等于0',
        'password.length'               => '密码长度6-18位',
        'password.different'            => '新密码与原密码不能相同',
        'confirm_password.confirm'      => '再次新密码不一致',
        'nickname.require'              => '昵称不能为空'
    ];
}